<template>
  <div class="skeleton-container">
    <!-- 首页骨架屏 -->
    <div v-if="type === 'home'" class="skeleton-home">
      <!-- Banner 骨架 -->
      <div class="skeleton-banner skeleton-shimmer"></div>

      <!-- 栏目骨架 -->
      <div v-for="i in 3" :key="i" class="skeleton-section">
        <div class="skeleton-section-header">
          <div class="skeleton-title skeleton-shimmer"></div>
          <div class="skeleton-tags">
            <span v-for="j in 4" :key="j" class="skeleton-tag skeleton-shimmer"></span>
          </div>
        </div>
        <div class="skeleton-grid">
          <div v-for="k in columnCount" :key="k" class="skeleton-card">
            <div class="skeleton-poster skeleton-shimmer"></div>
            <div class="skeleton-info">
              <div class="skeleton-text skeleton-shimmer"></div>
              <div class="skeleton-text-small skeleton-shimmer"></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 详情页骨架屏 -->
    <div v-else-if="type === 'detail'" class="skeleton-detail">
      <div class="skeleton-detail-header">
        <div class="skeleton-detail-poster skeleton-shimmer"></div>
        <div class="skeleton-detail-info">
          <div class="skeleton-title-large skeleton-shimmer"></div>
          <div class="skeleton-meta skeleton-shimmer"></div>
          <div class="skeleton-desc skeleton-shimmer"></div>
          <div class="skeleton-buttons">
            <div class="skeleton-btn skeleton-shimmer"></div>
            <div class="skeleton-btn skeleton-shimmer"></div>
          </div>
        </div>
      </div>
      <div class="skeleton-tabs skeleton-shimmer"></div>
      <div class="skeleton-content skeleton-shimmer"></div>
    </div>

    <!-- 列表页骨架屏 -->
    <div v-else-if="type === 'list'" class="skeleton-list">
      <div class="skeleton-filter skeleton-shimmer"></div>
      <div class="skeleton-grid">
        <div v-for="i in 12" :key="i" class="skeleton-card">
          <div class="skeleton-poster skeleton-shimmer"></div>
          <div class="skeleton-info">
            <div class="skeleton-text skeleton-shimmer"></div>
            <div class="skeleton-text-small skeleton-shimmer"></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 短视频骨架屏 -->
    <div v-else-if="type === 'shorts'" class="skeleton-shorts">
      <div class="skeleton-short-video skeleton-shimmer"></div>
      <div class="skeleton-short-actions">
        <div v-for="i in 4" :key="i" class="skeleton-action skeleton-shimmer"></div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
interface Props {
  type?: 'home' | 'detail' | 'list' | 'shorts'
}

const props = withDefaults(defineProps<Props>(), {
  type: 'home'
})

// 根据屏幕宽度计算列数
const columnCount = computed(() => {
  if (process.client) {
    const width = window.innerWidth
    if (width < 640) return 3
    if (width < 768) return 4
    if (width < 1024) return 6
    if (width < 1280) return 8
    return 10
  }
  return 6
})
</script>

<style scoped>
.skeleton-container {
  min-height: 100vh;
  padding: 54px 0 0;
  background: #111214;
}

/* 闪烁动画 */
.skeleton-shimmer {
  background: linear-gradient(
    90deg,
    #1a1b1e 25%,
    #2a2b2e 50%,
    #1a1b1e 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* 首页骨架屏 */
.skeleton-home {
  width: 100%;
}

.skeleton-banner {
  height: 40vh;
  width: 100%;
  border-radius: 0;
}

@media (min-width: 768px) {
  .skeleton-banner {
    height: 70vh;
  }
}

.skeleton-section {
  padding: 20px;
  margin-bottom: 20px;
}

.skeleton-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.skeleton-title {
  height: 24px;
  width: 120px;
  border-radius: 4px;
}

.skeleton-tags {
  display: flex;
  gap: 12px;
}

.skeleton-tag {
  display: inline-block;
  height: 20px;
  width: 50px;
  border-radius: 4px;
}

.skeleton-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, 1fr);
}

@media (min-width: 640px) {
  .skeleton-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (min-width: 768px) {
  .skeleton-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (min-width: 1024px) {
  .skeleton-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}

@media (min-width: 1280px) {
  .skeleton-grid {
    grid-template-columns: repeat(10, 1fr);
  }
}

.skeleton-card {
  width: 100%;
}

.skeleton-poster {
  width: 100%;
  padding-bottom: 133.33%; /* 3:4 比例 */
  border-radius: 6px;
  position: relative;
}

.skeleton-info {
  padding: 8px 0;
}

.skeleton-text {
  height: 16px;
  width: 100%;
  border-radius: 4px;
  margin-bottom: 6px;
}

.skeleton-text-small {
  height: 12px;
  width: 70%;
  border-radius: 4px;
}

/* 详情页骨架屏 */
.skeleton-detail {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.skeleton-detail-header {
  display: flex;
  gap: 30px;
  margin-bottom: 30px;
}

.skeleton-detail-poster {
  width: 200px;
  height: 280px;
  border-radius: 8px;
  flex-shrink: 0;
}

.skeleton-detail-info {
  flex: 1;
}

.skeleton-title-large {
  height: 32px;
  width: 300px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.skeleton-meta {
  height: 20px;
  width: 200px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.skeleton-desc {
  height: 60px;
  width: 100%;
  border-radius: 4px;
  margin-bottom: 20px;
}

.skeleton-buttons {
  display: flex;
  gap: 12px;
}

.skeleton-btn {
  height: 40px;
  width: 120px;
  border-radius: 20px;
}

.skeleton-tabs {
  height: 44px;
  width: 100%;
  border-radius: 4px;
  margin-bottom: 20px;
}

.skeleton-content {
  height: 300px;
  width: 100%;
  border-radius: 8px;
}

/* 列表页骨架屏 */
.skeleton-list {
  padding: 20px;
}

.skeleton-filter {
  height: 50px;
  width: 100%;
  border-radius: 8px;
  margin-bottom: 20px;
}

/* 短视频骨架屏 */
.skeleton-shorts {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.skeleton-short-video {
  width: 100%;
  height: 100%;
  max-width: 500px;
}

.skeleton-short-actions {
  position: absolute;
  right: 20px;
  bottom: 100px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.skeleton-action {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

/* 移动端适配 */
@media (max-width: 640px) {
  .skeleton-section {
    padding: 12px;
  }

  .skeleton-detail-header {
    flex-direction: column;
    align-items: center;
  }

  .skeleton-detail-poster {
    width: 150px;
    height: 210px;
  }
}
</style>